home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: calloc help needed
- Date: Fri, 16 Feb 96 20:47:41 GMT
- Organization: none
- Message-ID: <824503661snz@genesis.demon.co.uk>
- References: <1996Feb15.125431.7751@leeds.ac.uk> <4fvmgbINNbp0@keats.ugrad.cs.ubc.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4fvmgbINNbp0@keats.ugrad.cs.ubc.ca>
- c2a192@ugrad.cs.ubc.ca "Kazimir Kylheku" writes:
-
- >In article <1996Feb15.125431.7751@leeds.ac.uk>,
- >A M Casey <csyamc@scs.leeds.ac.uk> wrote:
- > >I'm trying to allocate enough memory for an array of strings, defined as
- > >char * MyArray[20].
-
- That defines an array of 20 pointers. You will have to set each pointer
- individually to point into a suitable array of characters.
-
- > >the only manual entry I have for calloc says that it needs two values, the
- > >number of elements, and the size of each, but how do I actually use it?
- > >
- > >MyArray = calloc(20,50);
-
- This is illegal with the definition of MyArray you have (you can't assign
- to an array). What you may want is:
-
- char (*MyArray)[50];
-
- where I take 50 to be the wize of each character array to be allocated for
- each string. However see the FAQ for more information about allocating
- '2D' arrays.
-
- >This is gives you much more space than you need for the array. A character's
- >size is not 50!
-
- But he asked for an array of 'strings' not an array of characters.
-
- > >doesnt work, as far as I can tell calloc returns an int.
-
- ANSI calloc returns void *.
-
- >It is probably "implicitly defined" to return an int, because you lack a
- >declaration. Try including the "malloc.h" header file.
-
- The correct header file to include is stdlib.h.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-